import Axios from 'axios'
import _ from 'loadsh'
import {
<% definitions.forEach( (element,index) => {  %><%- element.name.replace(/«/g, "").replace(/»/g, "") %>, <%})%>
} from './<%=outPutVariableFile %>'


/**
* <%=info.title %>
* @description <%=info.description %>
* @version <%=info.version %>
* @author <%=info.contact.name %>
* @authorEmail <%=info.contact.email %>
* @creator <%=creatorInfo.name %>
* @creatorEmail <%=creatorInfo.email %>
* @createDateTime <%=createDateTime %>
*/
export default class <%=className %> {

    constructor(params) {
        if (typeof params === 'string' || params==='' || !params) {
            this._buildDomain(params)
        } else {
            this._buildAxios(params)
        }
    }

    _buildAxios(axios) {
        this._axios = axios;
        // TODO 可以在这里初始化axios相关的配置
        // axios.defaults.headers =
    }

    _buildDomain(domain= '<%=basePath %>') {
        this._axios = Axios.create({
            baseURL: domain,
        })
        // TODO 可以在这里初始化axios相关的配置
        // axios.defaults.headers =
    }

<%methods.forEach(method=>{%>
    /**
     * <%=method.summary%>
     * @tags <%=method.tags.join(',')%>
     * @param data 请求参数
     * @param config AxiosRequestConfig 的增强型配置
     */
    <%=method.methodName %>(
        <% if(method.parameters) { %>data= <% if(method.parameters.length===1 && method.parameters[0].schema) {%><%=method.parameters[0].schema.value%>,<%} else {%>{<% method.parameters.forEach(param=>{ %>
            <%=param.name %>,<% }) %>
        },<%}%><% } else { %>data= {},<%}%>
        config= {}) {
        return <% if(['post','put','patch'].includes(method.method.toLocaleLowerCase())) { %>this._axios.<%=method.method.toLocaleLowerCase() %><<%-method.response %>>('<%-method.path %>', data, config);<% } else if(['get','delete','head','options'].includes(method.method.toLocaleLowerCase())) { %>this._axios.<%=method.method.toLocaleLowerCase() %><<%-method.response %>>('<%=method.path %>',_.merge({params: data}, config));<%}%>
    }
    <%})%>
}
